/**
 * 
 */
package autoUpdater.gui;

import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JProgressBar;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

/**
 * @author Christian
 * 
 */
public class UpdaterFrame extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1465641450956686541L;

	private JLabel jStatusLabel = null;
	
	private JLabel jDownloadSpeedLabel = null;
	
	private JProgressBar progressBar = null;
	
	private int geladenerWert = 0;
	
	private  volatile boolean closed = false;
	
	public UpdaterFrame(String version) {

		setTitle("AutoUpdater " + version);
		setLocationRelativeTo(null);
		
		setSize(450, 139);
		this.addWindowListener(new WindowAdapter() {
		 			
			public void windowClosing(WindowEvent e) {
		
				closed = true;
				dispose();
			}	
		});
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 426, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		getContentPane().setLayout(gridBagLayout);
		jStatusLabel = new JLabel("Staus");
		GridBagConstraints gbc_jStatusLabel = new GridBagConstraints();
		gbc_jStatusLabel.insets = new Insets(0, 0, 5, 0);
		gbc_jStatusLabel.gridx = 0;
		gbc_jStatusLabel.gridy = 1;
		getContentPane().add(jStatusLabel, gbc_jStatusLabel);
		jDownloadSpeedLabel = new JLabel("0 KB/s");
		GridBagConstraints gbc_jDownloadSpeedLabel = new GridBagConstraints();
		gbc_jDownloadSpeedLabel.insets = new Insets(0, 0, 5, 0);
		gbc_jDownloadSpeedLabel.gridx = 0;
		gbc_jDownloadSpeedLabel.gridy = 2;
		getContentPane().add(jDownloadSpeedLabel, gbc_jDownloadSpeedLabel);
		progressBar = new JProgressBar();
		GridBagConstraints gbc_progressBar = new GridBagConstraints();
		gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
		gbc_progressBar.insets = new Insets(5, 5, 0, 0);
		gbc_progressBar.gridx = 0;
		gbc_progressBar.gridy = 3;
		getContentPane().add(progressBar, gbc_progressBar);
	}
	
	public void setStatusText(String t) {

		jStatusLabel.setText(t);
	}
	
	public void setDownloadSpeedText(String t) {

		jDownloadSpeedLabel.setText(t);
	}
	
	public boolean isClosed() {
		
		return closed;
	}
	
	public void updateJProgressBar(final int wert) {

		if (geladenerWert == wert) {
			return;
		}
		geladenerWert = wert;
		progressBar.setValue(wert);
		progressBar.invalidate();
		progressBar.repaint();
		invalidate();
		repaint();
	}

	/**
	 * @param bool
	 */
	public void setIndeterminate(boolean bool) {

		progressBar.setIndeterminate(bool);
		
	}
}
